package com.javafactroy.kunlong.bip.icp.message.test.netty.codec;

import com.javafactroy.kunlong.bip.icp.message.test.base.TMsg;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
@Slf4j
public class TMsgByte2MsgDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        log.info("TMsgByte2MsgDecoder byteBuf=\r\n{}", ByteBufUtil.prettyHexDump(byteBuf));

        int len = byteBuf.readableBytes();
        byte[] bytes = new byte[len];
        byteBuf.readBytes(bytes);
        TMsg msg = new TMsg();
        msg.decode(bytes);
        list.add(msg);
        //ReferenceCountUtil.release(byteBuf);
    }
}
